import time
import datetime
import fcntl

class MyFile:
    @staticmethod
    def lock_file(fd):
        try:
            fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
            return True
        except:
            return False
    
    @staticmethod
    def wrtie_log(fd, log):
        fd.write(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        fd.write(":[")
        fd.write(log)
        fd.write("]\n")


